<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>编辑管理员账户</title>
</head>
<style type="text/css">
    body{
        background: url(image/add_bg.jpg);
        background-repeat: no-repeat;
        background-size: 100% 100%;
        min-height: 500px;
    }
    table{
        margin-top: 75px;
        margin-bottom:40px;
        width: 80%;
        min-height: 100px;
        border: 1px solid #fff;
    }
    td{
      border: 1px solid #ccc;
      overflow: hidden;
      text-align: center;

    }
    label{
      font-weight: bold;
    }
    div{
      margin-bottom:100px;
      width: 80%;
      border:1px solid #ccc;
      display: none;
    }
    input[type="text"]{
      width: 20%;
      height:25px;
      margin-left:5px;
      padding-left:10px;
    }
    input[type="button"]{
      width: 10%;
      height: 32px;
    }

</style>
<body style="background-color:#FFF;">
     <center>
      <table>
      	    <thead>
                  <tr>
                       <th>账号</th>
                       <th>密码</th>
                       <th>角色</th>
                       <th>删改</th>
                  </tr>
      	    </thead>
      	    <tbody>
      	    </tbody>
      </table>
      <div id="div">
           <label>修改：</label>
           <input type="text" name="text" id="edit_name"/>
           <input type="text" name="passwowrd" id="edit_password"/>
           <input type="text" name="type"  id="edit_role"/>
           <input type="button" value="提交" id="submit">
      </div>
    </center>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="../public/js/serverIp.js"></script>
<script type="text/javascript">
     
      $(function(){

        $.post(serverIp+"/Scauaie.com/user/show",null,function(data){
             var dataobj=JSON.parse(data);
             $("tbody").empty();
             $.each(dataobj,function(index,value){
                   $("tbody").append("<tr id='"+index+"' data='"+value.accountId+"'></tr>");
                   $("#"+index).append("<td class='account'>"+value.name+"</td>");
                   $("#"+index).append("<td class='password'>"+value.password+"</td>");
                   $("#"+index).append("<td class='role'>"+value.role+"</td>");
                   $("#"+index).append("<td class='td'><a href='javascript:;' class='edit'>编辑</a>|<a href='' class='delete'>删除</a></td>");
             })

            $(".edit").click(function(){
                  $("#edit_name").val($(this).parent().prevAll(".account").html()).attr("data",$(this).parent().parent().attr("data"));
                  $("#edit_password").val($(this).parent().prevAll(".password").html());
                  $("#edit_role").val($(this).parent().prevAll(".role").html());
                  $("#div").css({"display":"block"});
                  $(window).scrollTop(1000);
                  $("#submit").click(function(){
                       var datastr="account="+$("#edit_name").val()+"&password="+$("#edit_password").val()+"&role="+$("#edit_role").val()+"&id="+$("#edit_name").attr("data");
                       $.post(serverIp+"/Scauaie.com/user/addaccount",datastr,function(data){
                            var dataobj=JSON.parse(data);
                            if(dataobj.bool=="true"){
                                 window.location.href="account_edit.html";
                            }else{
                                 alert("修改失败,请再次尝试.")
                            }
                       },"html")

                  })

            })
              
            $(".delete").click(function(){
                   var yes=confirm("确定要删除吗？");
                  if(yes){
                    var datastr="id="+$(this).parent().parent().attr("data");
                    $.post(serverIp+"/Scauaie.com/user/delete",datastr,function(data){
                         var dataobj=JSON.parse(data);
                         if(dataobj.bool=="true"){
                              $(this).parent().parent().remove();
                              window.location.href="account_edit.html";
                         }else{
                             alert("删除失败,请重新尝试!");
                         }
                        
                    },"html")                 
                }
            })   

        },"html")

})

      
      
</script>
</body>
      
</html>